<template>
	<view class="container">
		<!--header-->
		<view class="tui-header-box" :style="{ height: height + 'px', background: 'rgba(255,255,255,' + opcity + ')' }">
			<view class="tui-header" :style="{ paddingTop: top + 'px', opacity: opcity }">商品详情</view>
			<view class="tui-header-icon" :style="{ marginTop: top + 'px' }">
				<view class="tui-icon-box" :style="{ backgroundColor: 'rgba(0, 0, 0,' + iconOpcity + ')' }" @tap="back">
					<tui-icon name="arrowleft" :size="30" :color="opcity >= 1 ? '#000' : '#fff'"></tui-icon>
				</view>

				<view class="tui-icon-box tui-icon-ml" :style="{backgroundColor: 'rgba(0, 0, 0,' + iconOpcity + ')'}"
					@tap.stop="openMenu">
					<tui-icon name="more-fill" :size="20" :color="opcity >= 1 ? '#000' : '#fff'"></tui-icon>
				</view>

			</view>
		</view>
		<!--header-->

		<!--banner-->
		<view class="tui-banner-swiper">
			<swiper :autoplay="true" :interval="5000" :duration="150" :circular="true"
				:style="{ height: scrollH + 'px' }" @change="bannerChange">
				<block v-for="(item, index) in detail.images" :key="index">
					<swiper-item :data-index="index" @tap.stop="previewImage(info.app.cdnurl+item)">
						<image :src="info.app.cdnurl+item" class="tui-slide-image"
							:style="{ height: scrollH + 'px' }" />
					</swiper-item>
				</block>
			</swiper>
			<!-- <view class="tui-video__box" @tap.stop="play">
				<image src="https://www.thorui.cn/images/mall/img_video_3x.png" mode="widthFix"></image>
				<view>00′30″</view>
			</view> -->
			<view class="tui-banner-tag">
				<tui-tag padding="12rpx 18rpx" type="translucent" shape="circleLeft" :scaleMultiple="0.82" originRight
					v-if="detail.images">{{ bannerIndex + 1 }}/{{ detail.images.length }}</tui-tag>
			</view>
		</view>

		<!--banner-->

		<view class="tui-pro-detail">
			<view class="tui-product-title tui-border-radius">
				<view class="tui-pro-pricebox tui-padding">
					<view class="tui-pro-price">
						<view>
							<text >￥</text>
							<text class="tui-price">{{detail.price[0] || 0}}</text>
							<text class="tui-price">+</text>
							<text class="tui-price" >{{selectShop.score || 0}}积分</text>
						</view>
						<!-- <tui-tag padding="10rpx 20rpx" size="24rpx" plain type="high-green" shape="circle" :scaleMultiple="0.8">新品</tui-tag> -->
					</view>
					<!-- <view class="tui-collection tui-size" @tap="collecting(detail)">
						<tui-icon :name="detail.favorite ? 'like-fill' : 'like'"
							:color="detail.favorite ? '#ff201f' : '#333'" :size="20"></tui-icon>
						<view class="tui-scale-collection" :class="{'tui-icon-red':detail.favorite}">收藏</view>
					</view> -->
					
				<!-- 	<view class="tui-collection tui-size" @tap="collecting(detail)">
						<view class="tui-scale-collection" :class="{'tui-icon-red':detail.favorite}" style="font-size: 32rpx;">已兑换{{detail.sales}}</view>
					</view> -->
					
				</view>
				<view class="tui-original-price tui-gray">
					价格
					<text class="tui-line-through">￥{{detail.original_price}}</text>
				</view>
				
		<!-- 		<view class="tui-pro-titbox">
					<view class="tui-pro-title">{{detail.title}}</view>
					<view class="tui-share-position" @tap="showSharePopup()">
						<tui-tag type="gray" shape="circleLeft" padding="12rpx 16rpx">
							<view class="tui-share-box">
								<tui-icon name="partake" color="#999" :size="15"></tui-icon>
								<text class="tui-share-text tui-gray tui-size">分享</text>
							</view>
						</tui-tag>
					</view>
				</view> -->
			
			</view>
			<!-- <button @click="openSkuPopup()">打开SKU组件</button> -->


			<view class="tui-basic-info tui-mtop tui-radius-all">
				<!-- <view class="tui-list-cell" @tap="showPopup"> -->

				<view class="tui-list-cell" @click="openSkuPopup()">
					<view class="tui-bold tui-cell-title">选择</view>
					<view class="tui-selected-box" v-if="detail.goods_sku_text">{{detail.goods_sku_text.join(',')}}
					</view>
					<!-- <view class="tui-selected-box" v-else>选择商品规格</view> -->
					<view class="" v-if="selectShop && selectShop.buy_num">{{ selectShop.buy_num }}个</view>
					<view class="" v-else>1个</view>
					<view class="tui-ml-auto">
						<tui-icon name="more-fill" :size="20" color="#666"></tui-icon>
					</view>
				</view>
				<view class="tui-guarantee" v-if="detail.service">
					<view class="tui-guarantee-item" v-for="(item,index) in detail.service" :key="index">
						<tui-icon name="circle-selected" :size="14" color="#999"></tui-icon>
						<text class="tui-pl">{{item.name}}</text>
					</view>

				</view>
			</view>
			<view class="tui-cmt-box tui-mtop tui-radius-all">
				<view class="tui-list-cell tui-last tui-between">
					<view class="tui-bold tui-cell-title" style="display: flex;align-items: center;">
						<view class="">评价</view>
						<view class="" style="color: #999999;font-size: 22rpx;" v-if="commentList && commentList.total">
							({{commentList.total}})</view>
					</view>
					<view class="tui-flex-center" @tap="evaluate">
						<text class="tui-cmt-all">查看全部</text>
						<!-- <tui-icon name="more-fill" :size="20" color="#ff201f"></tui-icon> -->
					</view>
				</view>

				<view class="" v-if="commentList && commentList.data">
					<view class="tui-cmt-content tui-padding" v-for="(item,index) in commentList.data" :key="index">
						<view class="tui-cmt-user">
							<image :src="info.app.cdnurl+item.user_avatar" class="tui-acatar"></image>
							<view>{{item.user_nickname}}</view>
							<tn-rate v-model="item.level" :count="5" activeColor="red" disabled
								style="margin-left: 20rpx;"></tn-rate>

						</view>
						<view class="tui-cmt">{{item.content}}</view>
						<!-- <view class="tui-attr">颜色：叠层钛钢流苏耳环（A74）</view> -->
						<view class="" v-if="item.images" style="display: flex;">
							<scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="120"
								style="white-space: nowrap;">
								<image :src="info.app.cdnurl+itemSub"
									style="width: 140rpx;height: 140rpx;margin-right: 20rpx;"
									v-for="(itemSub,index) in item.images" :key="index"
									@click="proveImage(info.app.cdnurl+itemSub)"></image>

							</scroll-view>

						</view>
						<view class="" style="height: 1px;background: #eee;margin: 10rpx 0;"></view>
					</view>
				</view>

				<view class="tui-cmt-btn">
					<tui-button width="240rpx" height="64rpx" :size="24" type="black" plain shape="circle"
						@click="evaluate">查看全部评价</tui-button>
				</view>
			</view>

			<view class="tui-nomore-box">
				<tui-nomore text="宝贝详情" backgroundColor="#f7f7f7"></tui-nomore>
			</view>
			<view class="tui-product-img tui-radius-all">
				<mp-html :content="detail.content"></mp-html>
			</view>
			<tui-nomore text="已经到最底了" backgroundColor="#f7f7f7"></tui-nomore>
			<view class="tui-safearea-bottom"></view>
		</view>

		<!--底部操作栏-->
		<view class="tui-operation">
			<view class="tui-operation-left tui-col-5">
				<view class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150">
					<button open-type="contact"
						style="background: none;display: flex;align-items: center;flex-direction: column;">
						<tui-icon name="kefu" :size="22" color="#333"
							style="height: 45rpx;line-height: 45rpx;"></tui-icon>
						<text class="tui-operation-text tui-scale-small"
							style="height: 20rpx;font-size: 26rpx;line-height: 20rpx;margin-top: 8rpx;">客服</text>
					</button>
				</view>
				<!-- <view class="tui-operation-item" hover-class="tui-opcity" :hover-stay-time="150"
					@tap="collecting(detail)">
					<text :class="detail.favorite?'tn-icon-star-fill tn-color-red' :'tn-icon-star'"
						style="font-size: 50rpx;"></text>
					<view class="tui-operation-text tui-scale-small">收藏</view>
				</view> -->
			</view>
			<view class="tui-operation-right tui-right-flex tui-col-7 tui-btnbox-5">
			<!-- 	<view class="tui-flex-1">
					<tui-button height="68rpx" :size="26" type="danger" shape="circle"
						@click="submit(2)">加入购物车</tui-button>
				</view> -->
				<view class="tui-flex-1">
					<tui-button height="68rpx" :size="26" type="warning" shape="circle"
						@click="submit(3)">立即兑换</tui-button>
				</view>
			</view>
		</view>

		<!--底部操作栏-->

		<!--顶部下拉菜单-->
		<tui-top-dropdown backgroundColor="rgba(76, 76, 76, 0.95)" :show="menuShow" :height="0" @close="closeMenu">
			<view class="tui-menu-box tui-padding tui-ptop">
				<view class="tui-menu-header" :style="{ paddingTop: top + 'px' }">功能直达</view>
				<view class="tui-menu-itembox">
					<block v-for="(item, index) in topMenu" :key="index">
						<view class="tui-menu-item" hover-class="tui-opcity" :hover-stay-time="150"
							@tap="btnTopMenu(index)">
							<view class="tui-badge-box">
								<tui-icon :name="item.icon" color="#fff" :size="item.size"></tui-icon>
							</view>
							<view class="tui-menu-text">{{ item.text }}</view>
						</view>
					</block>
				</view>
				<view class="tui-icon-up_box">
					<tui-icon name="up" color="#fff" :size="26" @click="closeMenu"></tui-icon>
				</view>
			</view>
		</tui-top-dropdown>
		<!---顶部下拉菜单-->





		<!--底部选择层-->
		<tui-bottom-popup :show="popupShow" @close="hidePopup">
			<view class="tui-popup-box">
				<view class="tui-product-box tui-padding">
					<image v-if="detail.images" :src="info.app.cdnurl+detail.images[0]" class="tui-popup-img">
					</image>
					<view class="tui-popup-price">
						<view class="tui-amount tui-bold">￥49.00</view>
						<view class="tui-number">编号:4373299399393</view>
					</view>
				</view>
				<scroll-view scroll-y class="tui-popup-scroll">
					<view class="tui-scrollview-box">
						<view class="tui-number-box tui-bold tui-attr-title">
							<view class="tui-attr-title">数量</view>
							<tui-numberbox :max="99" :min="1" :value="value" @change="change"></tui-numberbox>
						</view>


						<view class="" v-for="item in detail.skus" :key="item.id">
							<view class="tui-bold tui-attr-title">{{item.name}}</view>
							<view class="tui-attr-box">
								<view class="tui-attr-item" :class="itemSub.id==current?'tui-attr-active':''"
									v-for="(itemSub,index) in item.children" :key="itemSub.id"
									@click="setSku(itemSub.id)">{{itemSub.name}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
				<view class="tui-operation tui-operation-right tui-right-flex tui-popup-btn">
					<view class="tui-flex-1">
						<tui-button height="72rpx" :size="28" type="danger" shape="circle"
							@click="submit">加入购物车</tui-button>
					</view>
					<view class="tui-flex-1">
						<tui-button height="72rpx" :size="28" type="warning" shape="circle"
							@click="submit">立即购买</tui-button>
					</view>
				</view>
				<view class="tui-right">
					<tui-icon name="close-fill" color="#999" :size="20" @click="hidePopup"></tui-icon>
				</view>
			</view>
		</tui-bottom-popup>
		<!--底部选择层-->

		<!--底部分享弹层-->
		<tui-bottom-popup :show="sharePopup" @close="hideSharePopup">
			<view class="tui-share__box">
				<view class="tui-share__header">
					<text>分享</text>
					<view class="tui-close__box" @tap="hideSharePopup">
						<tui-icon name="shut" :size="20" color="#C9C9C9"></tui-icon>
					</view>
				</view>
				<view class="tui-share__list">
					<button open-type="share" class="tui-share-btn" @tap="onShare">
						<view class="tui-share__item">
							<image
								src="https://oss.taoding1688.com/static/uniapp/static/images/mall/icon_popup_share.png">
							</image>
							<view class="tui-share__text">分享给好友</view>
						</view>
					</button>
					<view class="tui-share__item" @tap="createPoster">
						<image src="https://oss.taoding1688.com/static/uniapp/static/images/mall/icon_popup_poster.png">
						</image>
						<view class="tui-share__text">生成分享海报</view>
					</view>
				</view>
			</view>
		</tui-bottom-popup>
		<!--底部分享弹层-->
		<canvas :style="{ width: winWidth + 'px', height: winHeight + 'px' }" canvas-id="posterId" id="posterId"
			class="tui-poster__canvas"></canvas>
		<tui-modal custom :show="modalShow" backgroundColor="transparent" padding="0" @cancel="hideModal">
			<view class="tui-poster__box" :style="{marginTop:height+'px'}">
				<image src="https://oss.taoding1688.com/static/uniapp/static/images/mall/icon_popup_closed.png"
					class="tui-close__img" @tap.stop="hideModal">
				</image>
				<image :src="posterImg" v-if="posterImg" class="tui-poster__img"></image>
				<tui-button type="danger" width="460rpx" height="80rpx" shape="circle"
					@click="savePic">保存图片</tui-button>
				<view class="tui-share__tips">保存图片到手机相册后，将图片分享到您的圈子</view>
			</view>
		</tui-modal>
		<view class="mask" catchtouchmove="preventTouchMove" v-if="couponshow == true" @tap="hidecoupon"></view>
		<view class="coupon" :style="'bottom:' + (couponshow == true ? '0px':'')">
			<scroll-view class="scrolls" scroll-y>
				<!-- colors:按钮颜色 couponList:优惠卷列表数据  @onReceive：领取或立即使用按钮事件 -->
				<cc-defineCoupon colors="#fa436a" :couponList="popupList" @onReceive="onReceive"></cc-defineCoupon>

			</scroll-view>
		</view>
		<view v-if="qrCode == ''">
			<QRCode ref="qrcode" />
		</view>


		<vk-data-goods-sku-popup ref="skuPopup" v-model="skuKey" border-radius="20" :z-index="990"
			:localdata="goodsInfo" :mode="skuMode" @open="onOpenSkuPopup" @close="onCloseSkuPopup" @add-cart="addCart"
			@buy-now="buyNow" @nextTick="nextTick"></vk-data-goods-sku-popup>



	</view>
</template>

<script>
	import {
		getListByGoods,
		getGoodsDetail,
		getCommemtRow,
		postShopupdate,
		getGoodsLogFavorite,
		getScoreShop
	} from '@/apis'
	import {
		days
	} from '@/util/auth'
	import QRCode from "@/components/qr_code/qrcode.vue"

	const thorui = require('@/components/common/tui-clipboard/tui-clipboard.js');
	const poster = require('@/components/common/tui-poster/tui-poster.js');
	import {
		shartInfo
	} from "@/util/share.js"
	export default {
		components: {
			QRCode
		},
		data() {
			return {
				qrCode: '', // 二维码
				popupList: {},
				selectShop: {},
				// 是否打开SKU弹窗
				skuKey: false,
				// SKU弹窗模式
				skuMode: 1,
				// 后端返回的商品信息
				goodsInfo: {},
				current: 0,
				couponshow: false,
				couponList: [],
				detail: {}, //商品详情
				height: 64, //header高度
				top: 26, //标题图标距离顶部距离
				scrollH: 0, //滚动总高度
				opcity: 0,
				iconOpcity: 0.5,
				banner: [],
				bannerIndex: 0,
				topMenu: [{
						icon: 'home',
						text: '首页',
						size: 23,
						badge: 0
					},
					{
						icon: 'people',
						text: '我的',
						size: 26,
						badge: 0
					},
					{
						icon: 'cart',
						text: '购物车',
						size: 23,
						badge: 2
					},
					{
						icon: 'feedback',
						text: '我要反馈',
						size: 23,
						badge: 0
					}
				],
				menuShow: false,
				popupShow: false,
				value: 1,
				collected: false,
				sharePopup: false,
				posterImg: '',
				winWidth: uni.upx2px(560 * 2),
				winHeight: uni.upx2px(890 * 2),
				modalShow: false,
				index: null,
				currentPage: 3,
				commentList: {},
				qrSize: 100, // 二维码大小
				shareDetail: {}
			};
		},
		onLoad: function(options) {
			this.index = options.index
			if (options.index) {
				this.getCoupon(options.index)
				this.getDetails(options.index)
				this.getCommemt(options.index)
			}
			let obj = {};
			// #ifdef MP-WEIXIN
			obj = wx.getMenuButtonBoundingClientRect();
			// #endif
			// #ifdef MP-BAIDU
			obj = swan.getMenuButtonBoundingClientRect();
			// #endif
			// #ifdef MP-ALIPAY
			my.hideAddToDesktopMenu();
			// #endif

			setTimeout(() => {
				uni.getSystemInfo({
					success: res => {
						this.width = obj.left || res.windowWidth;
						this.height = obj.top ? obj.top + obj.height + 8 : res.statusBarHeight +
							44;
						this.top = obj.top ? obj.top + (obj.height - 32) / 2 : res
							.statusBarHeight + 6;
						this.scrollH = res.windowWidth;
					}
				});
			}, 0);

		},
		onShareAppMessage(res) {
			let ress = shartInfo()
			return {
				title: this.info.app.name,
				path: `/templatePage/productDetail/productDetail?index=${this.detail.id}`,
				imageUrl: `${this.info.app.cdnurl}${this.detail.image}`,
			};
		},
		mounted() {
			let _this = this
			let params = {
				query: this.detail.id,
				page: 2
			}
			let res = shartInfo({
				params
			})
			let str = `/pages/index/index?${res.query}`
			let paths = {
				"path": str
			}
			const encodePath = encodeURIComponent(JSON.stringify(paths))
			let url =`https://oss.taoding1688.com/addons/shop/third.wechat/wxacode?platform=miniProgram&payload=${encodePath}`
				uni.downloadFile({
					url: url,
					success: (downloadRes) => {
						if (downloadRes.statusCode == 200) {
							_this.qrCode = downloadRes.tempFilePath
						}
					},
					failure: (err) => {
						console.log('下载文件失败', err);
					}
				});

		},
		methods: {
			// 创建二维码
			canvasCreate() {

			},
			proveImage(img) {
				uni.previewImage({
					urls: [img],
				});
			},
			formatSales(type, num) {
				num = num + '';
				if (type === 'exact') {
					return '已售' + num;
				} else {
					if (num < 10) {
						return '销量≤10';
					} else {
						let a = Math.pow(10, num.length - 1);
						return '已售' + parseInt(num / a) * a + '+';
					}
				}
			},

			// 初始化
			init(options = {}) {},
			// 获取商品信息，并打开sku弹出
			openSkuPopup() {
				/**
				 * 获取商品信息
				 * 这里可以看到每次打开SKU都会去重新请求商品信息,为的是每次打开SKU组件可以实时看到剩余库存
				 */
				// 此处写接口请求，并将返回的数据进行处理成goodsInfo的数据格式，
				// goodsInfo是后端返回的数据
				this.goodsInfo = {
					id: this.detail.id,
					name: this.detail.title,
					goods_thumb: `${this.info.app.cdnurl}${this.detail.image}`,
					sku_list: this.detail.sku_prices,
					spec_list: this.detail.skus,
					stock:this.detail.stock,
					type:1
				}
				this.skuKey = true;
			},
			// sku组件 开始-----------------------------------------------------------
			onOpenSkuPopup() {
				console.log("监听 - 打开sku组件");
			},
			onCloseSkuPopup() {
				console.log("监听 - 关闭sku组件");
			},
			submit(index) {
				this.skuMode = index
				this.openSkuPopup()

			},
			// 加入购物车前的判断
			addCartFn(obj) {
				let {
					selectShop
				} = obj;
				// 模拟添加到购物车,请替换成你自己的添加到购物车逻辑
				let res = {};
				let name = selectShop.goods_name;
				if (selectShop.sku_name != "默认") {
					name += "-" + selectShop.sku_name_arr;
				}
				res.msg = `${name} 已添加到购物车`;
				if (typeof obj.success == "function") obj.success(res);
			},
			// 加入购物车按钮
			async addCart(selectShop) {
				let obj = {
					order_type: "inc",
					goods_id: this.detail.sku_prices[0].goods_id,
					goods_num: this.selectShop.buy_num || 1,
					goods_sku_price_id: this.detail.sku_prices[0].id,
				}
				let res = await this.addShop(obj)
				if (res.code == 1) {
					uni.showToast({
						title: '~已添加到购物车',
						icon: 'none'
					})
					this.skuKey = false;
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}



				// if (this.detail.skus.length >= 1) {
				// 	if (this.selectShop.buy_num >= 1 && this.selectShop.goods_id && this.selectShop.price) {
				// 		uni.navigateTo({
				// 			url: '/templatePage/submitOrder/submitOrder'
				// 		});
				// 	} else {
				// 		this.toast('请选择规格')
				// 		this.openSkuPopup()
				// 	}
				// } else {
				// 	let obj = {
				// 		order_type: "inc",
				// 		goods_id: this.detail.sku_prices[0].goods_id,
				// 		goods_num: this.selectShop.buy_num || 1,
				// 		goods_sku_price_id: this.detail.sku_prices[0].id,
				// 	}
				// 	console.log(obj, 'resresresresresres')
				// 	let res = await this.addShop(obj)
				// 	if (res.code == 1) {
				// 		uni.showToast({
				// 			title: '~已添加到购物车',
				// 			icon: 'none'
				// 		})
				// 		this.skuKey = false;
				// 	} else {
				// 		uni.showToast({
				// 			title: res.msg,
				// 			icon: 'none'
				// 		})
				// 	}
				// }
			},
			//立即获取
			nextTick(selectShop) {
				this.selectShop = selectShop
				console.log(this.selectShop,'this.selectShop')
				if (selectShop.price) {
					this.detail.price[0] = selectShop.price
				}
				if (selectShop.goods_sku_text) {
					this.detail.goods_sku_text = selectShop.goods_sku_text
				}
			},
			// 立即购买
			buyNow(selectShop) {
				if (this.detail.skus.length >= 1) {
					if (this.selectShop.buy_num >= 1 && this.selectShop.goods_id && this.selectShop.price) {
						let obj = {
							order_type: "score",
							goods_list: [{
								goods_id: selectShop.goods_id,
								goods_sku_price_id: selectShop.id,
								goods_num: selectShop.buy_num || 1
							}]
						}
						uni.navigateTo({
							url: `/templatePage/submitOrder/submitOrders?data=${JSON.stringify(obj)}`
						});
					} else {
						this.toast('请选择规格')
						this.openSkuPopup()
					}
				} else {
					let obj = {
						order_type: "score",
						goods_list: [{
							goods_id: this.detail.sku_prices[0].goods_id,
							goods_sku_price_id: this.detail.sku_prices[0].id,
							goods_num: this.selectShop.buy_num || 1
						}]
					}
					uni.navigateTo({
						url: `/templatePage/submitOrder/submitOrders?data=${JSON.stringify(obj)}`
					});
				}
			},
			toast(msg) {
				uni.showToast({
					title: msg,
					icon: "none"
				});
			},


			async addShop(obj) {
				let res = await postShopupdate(obj)
				return res
			},
			async setSku(index) {
				this.current = index
			},
			async getCoupon(id) {
				let res = await getListByGoods(id)
				res.data.forEach(item => {
					// 更新 createtime 和 updatetime 字段
					item.get_end_time = item.get_end_time.split(' ')[0];
					item.get_start_time = item.get_start_time.split(' ')[0];
				});

				this.popupList = res.data
			},
			async getDetails(id) {

				let res = await getScoreShop(id)
				this.detail = res.data
				// if(res.data.image){
				// 	this.detail.image=[res.data.video,res.data.image]
				// }
			},

			async getCommemt(id) {
				let res = await getCommemtRow(id, this.currentPage, 1, 10)
				if (res.data && res.data.data) {
					this.commentList = res.data
				}
			},



			bannerChange: function(e) {
				this.bannerIndex = e.detail.current;
			},
			previewImage: function(e) {
				uni.previewImage({
					urls: [e]
				});
			},
			back: function() {
				uni.navigateBack();
			},
			openMenu: function() {
				this.menuShow = true;
			},
			closeMenu: function() {
				this.menuShow = false;
			},
			showPopup: function() {
				this.popupShow = true;
			},
			hidePopup: function() {
				this.popupShow = false;
				// uni.reLaunch({
				// 	url: '/pages/index/index?index=3'
				// });
			},
			//跳转购物车
			goToVip() {
				uni.switchTab({
					url: '/pages/vip/vip'
				})
			},
			//生成海报
			poster() {
				this.modalShow = true;
				this.tui.toast('海报生成中，请稍后');
				setTimeout(() => {
					this.posterImg = 'https://www.tuikebao.com/static/images/mall/poster.png';
					this.modalShow = false;
					this.tui.toast('长按图片保存至相册');
				}, 1000);
			},
			showSharePopup: function() {
				this.sharePopup = true;
			},
			change: function(e) {
				this.value = e.value;
			},
			async collecting(item) {
				let res = await getGoodsLogFavorite(item.id)
				await this.getDetails(this.index)
				// this.collected = !this.collected;
			},
			evaluate() {
				// this.tui.href('/pages/index/goodsEvaluate/goodsEvaluate')
				uni.navigateTo({
					url: `/templatePage/goodsEvaluate/goodsEvaluate?index=${this.index}`
				});
			},
			common: function() {
				this.tui.toast('功能开发中~');
			},
			btnTopMenu(index) {
				this.closeMenu()
				// if (index == 4) {
				// 	uni.makePhoneCall({
				// 		phoneNumber: "10086"
				// 	})
				// } else if (index == 6) {
				// 	this.showSharePopup()
				// } else if (index == 5) {
				// 	uni.navigateTo({
				// 		url: '/discountPage/feedback/feedback'
				// 	})
				// } else {

				// }

				let url = {
					0: "/pages/index/index",
					1: '/pages/tuniao/tuniao',
					2: '/pages/vip/vip',
					3: '/discountPage/feedback/feedback'
				} [index];
				if (index == 3) {
					uni.navigateTo({
						url: '/discountPage/feedback/feedback'
					})
				} else {
					uni.switchTab({
						url: url
					})
				}
			},

			coupon() {
				uni.navigateTo({
					url: '/pages/index/coupon/coupon'
				});
			},
			onShare() {
				this.hideSharePopup()
				//#ifdef APP-PLUS
				plus.share.sendWithSystem({
						content: this.info.app.name,
						href: this.shareDetail.link
					},
					function() {
						console.log('分享成功');
					},
					function(e) {
						console.log('分享失败：' + JSON.stringify(e));
					}
				);
				//#endif
				// #ifdef H5
				thorui.getClipboardData(this.shareDetail.link, res => {
					if (res) {
						uni.showToast({
							title: '链接复制成功，赶快去分享吧~',
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: '链接复制失败',
							icon: 'none'
						})
					}
				});
				// #endif
			},
			shop() {
				uni.navigateTo({
					url: '/discountPage/shop/shop'
				})
			},
			play() {
				uni.navigateTo({
					url: '/pages/index/video/video',
					animationType: 'zoom-out'
				})
			},
			showSharePopup() {
				this.sharePopup = true
			},
			hideSharePopup() {
				this.sharePopup = false
			},
			async createPoster() {
				this.hideSharePopup()
				if (this.posterImg) {
					this.modalShow = true;
					return;
				}
				uni.showLoading({
					mask: true,
					title: '图片生成中...'
				});
				let str = this.info.app.cdnurl + this.detail.image
				let mainPic = await poster.getImage(str);
				// let qrcode = await poster.getImage('https://thorui.cn/extend/share/applets.png');
				console.log(this.qrCode, 'this.qrCode')
				// #ifdef MP-WEIXIN
				await poster.removeSavedFile();
				// #endif
				if (mainPic && this.qrCode) {
					const imgs = {
						mainPic: mainPic,
						qrcode: this.qrCode
					};
					let text = this.detail.title;
					poster.drawGoodsPoster('posterId', this.winWidth, this.winHeight, imgs, text, this.detail.price[0],
						this.detail.original_price,
						'小程序',
						res => {
							uni.hideLoading();
							if (res) {
								this.posterImg = res;
								console.log(this.posterImg, 'this.posterImg')
								setTimeout(() => {
									this.modalShow = true;
								}, 60);
							} else {
								this.tui.toast('生成海报失败,请稍后再试');
							}
						});
				} else {
					uni.hideLoading();
					this.tui.toast('生成海报图片下载失败,请稍后再试');
				}
			},
			hideModal() {
				this.modalShow = false;
			},
			savePic() {
				if (this.posterImg) {
					// #ifdef H5
					uni.previewImage({
						urls: [this.posterImg]
					});
					// #endif

					// #ifndef H5
					poster.saveImage(this.posterImg);
					// #endif

					this.hideModal();
				}
			},
			// 打开优惠券弹框
			opencoupon() {
				if (this.popupList.length > 0) {
					this.couponshow = true
				} else {
					uni.showToast({
						title: '暂无优惠券',
						icon: 'none'
					})
				}
			},
			// 关闭优惠券弹框 
			hidecoupon() {
				this.couponshow = false
			},
			//领取优惠券 立即使用事件
			onReceive(item, index) {
				this.getCoupon(this.index)
				// if (item.status == 1) {
				// 	// 立即使用 事件
				// } else {
				// 	this.couponList[index].status = 1 //领取成功
				// 	uni.showToast({
				// 		title: '领取成功',
				// 		icon: 'none'
				// 	})
				// }
			},

		},
		onPageScroll(e) {
			let scroll = e.scrollTop <= 0 ? 0 : e.scrollTop;
			let opcity = scroll / this.scrollH;
			if (this.opcity >= 1 && opcity >= 1) {
				return;
			}
			this.opcity = opcity;
			this.iconOpcity = 0.5 * (1 - opcity < 0 ? 0 : 1 - opcity);
		}
	};
</script>

<style>
	.mask {
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		background: #000;
		z-index: 900;
		opacity: 0.7;
	}

	/* 优惠券 */
	.coupon {
		background-color: #fff;
		border-radius: 10upx 10upx 0 0;
		position: fixed;
		left: 0;
		bottom: -1000upx;
		z-index: 999;
		transition: all 0.3s;
	}

	.scrolls {
		width: 100vw;
		height: 60vh;
		padding-top: 10upx;
		z-index: 500;
	}

	page {
		background-color: #f7f7f7;
	}

	.container {
		padding-bottom: 110rpx;
	}

	.tui-header-box {
		width: 100%;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 995;
	}

	.tui-header {
		width: 100%;
		font-size: 18px;
		line-height: 18px;
		font-weight: 500;
		height: 32px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-header-icon {
		position: fixed;
		top: 0;
		left: 10px;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		height: 32px;
		transform: translateZ(0);
		z-index: 9999;
	}

	.tui-header-icon .tui-badge {
		background: #e41f19 !important;
		position: absolute;
		right: -4px;
	}

	.tui-icon-ml {
		margin-left: 20rpx;
	}

	.tui-icon-box {
		position: relative;
		height: 20px !important;
		width: 20px !important;
		padding: 6px !important;

		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-banner-swiper {
		position: relative;
	}

	.tui-video__box {
		width: 166rpx;
		height: 60rpx;
		position: absolute;
		left: 50%;
		bottom: 50rpx;
		transform: translateX(-50%);
		z-index: 2;
	}

	.tui-video__box image {
		width: 166rpx;
		height: 60rpx;
	}

	.tui-video__box view {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		position: absolute;
		left: 0;
		top: 0;
		display: flex;
		align-items: center;
		padding-left: 66rpx;
		box-sizing: border-box;
	}

	.tui-banner-tag {
		position: absolute;
		color: #fff;
		bottom: 30rpx;
		right: 0;
	}

	.tui-slide-image {
		width: 100%;
		display: block;
	}

	/*顶部菜单*/

	.tui-menu-box {
		box-sizing: border-box;
	}

	.tui-menu-header {
		font-size: 34rpx;
		color: #fff;
		height: 32px;
		display: flex;
		align-items: center;
	}

	.tui-menu-itembox {
		color: #fff;
		padding: 40rpx 10rpx 0 10rpx;
		box-sizing: border-box;
		display: flex;
		flex-wrap: wrap;
		font-size: 26rpx;
	}

	.tui-menu-item {
		width: 22%;
		height: 160rpx;
		border-radius: 24rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		background: rgba(0, 0, 0, 0.4);
		margin-right: 4%;
		margin-bottom: 4%;
	}

	.tui-menu-item:nth-of-type(4n) {
		margin-right: 0;
	}

	.tui-badge-box {
		position: relative;
	}

	.tui-badge-box .tui-badge-class {
		position: absolute;
		top: -8px;
		right: -8px;
	}

	.tui-msg-badge {
		top: -10px;
	}

	.tui-icon-up_box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-menu-text {
		padding-top: 12rpx;
	}

	.tui-opcity .tui-menu-text,
	.tui-opcity .tui-badge-box {
		opacity: 0.5;
		transition: opacity 0.2s ease-in-out;
	}

	/*顶部菜单*/

	/*内容 部分*/

	.tui-padding {
		padding: 0 30rpx;
		box-sizing: border-box;
	}

	.tui-ml-auto {
		margin-left: auto;
	}

	/* #ifdef H5 */
	.tui-ptop {
		padding-top: 44px;
	}

	/* #endif */

	.tui-size {
		font-size: 24rpx;
		line-height: 24rpx;
	}

	.tui-gray {
		color: #999;
	}

	.tui-icon-red {
		color: #ff201f;
	}

	.tui-border-radius {
		border-bottom-left-radius: 24rpx;
		border-bottom-right-radius: 24rpx;
		overflow: hidden;
	}

	.tui-radius-all {
		border-radius: 24rpx;
		overflow: hidden;
	}

	.tui-mtop {
		margin-top: 26rpx;
	}

	.tui-pro-detail {
		box-sizing: border-box;
		color: #333;
	}

	.tui-product-title {
		background: #fff;
		padding: 30rpx 0;
	}

	.tui-pro-pricebox {
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #ff201f;
		font-size: 36rpx;
		font-weight: bold;
		line-height: 44rpx;
	}

	.tui-pro-price {
		display: flex;
		align-items: center;
	}

	.tui-price {
		font-size: 58rpx;
	}

	.tui-original-price {
		font-size: 26rpx;
		line-height: 26rpx;
		padding: 10rpx 30rpx;
		box-sizing: border-box;
	}

	.tui-line-through {
		text-decoration: line-through;
	}

	.tui-collection {
		color: #333;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		height: 44rpx;
	}

	.tui-scale-collection {
		transform: scale(0.7);
		transform-origin: center 90%;
		line-height: 24rpx;
		font-weight: normal;
		margin-top: 4rpx;
	}

	.tui-pro-titbox {
		font-size: 32rpx;
		font-weight: 500;
		position: relative;
		padding: 0 150rpx 0 30rpx;
		box-sizing: border-box;
	}

	.tui-pro-title {
		padding-top: 20rpx;
	}

	.tui-share-btn {
		flex: 1;
		display: block;
		background: transparent;
		margin: 0;
		padding: 0;
		border-radius: 0;
		border: 0;
		line-height: 1;
	}

	.tui-share-btn::after {
		border: 0;
	}

	.tui-share-box {
		display: flex;
		align-items: center;
	}

	.tui-share-position {
		position: absolute;
		right: 0;
		top: 30rpx;
	}

	.tui-share-text {
		padding-left: 8rpx;
	}

	.tui-sub-title {
		padding: 20rpx 0;
		line-height: 32rpx;
	}

	.tui-sale-info {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-top: 30rpx;
	}

	.tui-discount-box {
		background: #fff;
	}

	.tui-list-cell {
		width: 100%;
		position: relative;
		display: flex;
		align-items: center;
		font-size: 26rpx;
		line-height: 26rpx;
		padding: 36rpx 30rpx;
		box-sizing: border-box;
	}

	.tui-right {
		position: absolute;
		right: 30rpx;
		top: 30rpx;
	}

	.tui-top40 {
		top: 40rpx !important;
	}

	.tui-bold {
		font-weight: bold;
	}

	.tui-list-cell::after {
		content: '';
		position: absolute;
		border-bottom: 1rpx solid #eaeef1;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		bottom: 0;
		right: 0;
		left: 126rpx;
	}

	.tui-last::after {
		border-bottom: 0 !important;
	}

	.tui-flex-center {
		display: flex;
		align-items: center;
	}


	.tui-cell-title {
		/* width: 66rpx; */
		padding-right: 30rpx;
		flex-shrink: 0;
	}

	.tui-promotion-box {
		display: flex;
		align-items: center;
		padding: 10rpx 0;
		width: 80%;
	}

	.tui-promotion-box text {
		width: 70%;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.tui-basic-info {
		background: #fff;
	}

	.tui-addr-box {
		width: 76%;
	}

	.tui-addr-item {
		padding: 10rpx;
		line-height: 34rpx;
	}

	.tui-guarantee {
		background: #fdfdfd;
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx 30rpx 30rpx 30rpx;
		font-size: 24rpx;
	}

	.tui-guarantee-item {
		color: #999;
		padding-right: 30rpx;
		padding-top: 10rpx;
	}

	.tui-pl {
		padding-left: 4rpx;
	}

	.tui-cmt-box {
		background: #fff;
	}

	.tui-between {
		justify-content: space-between !important;
	}

	.tui-cmt-all {
		color: #ff201f;
		padding-right: 8rpx;
	}

	.tui-cmt-content {
		font-size: 26rpx;
	}

	.tui-cmt-user {
		display: flex;
		align-items: center;
	}

	.tui-acatar {
		width: 60rpx;
		height: 60rpx;
		border-radius: 30rpx;
		display: block;
		margin-right: 16rpx;
	}

	.tui-cmt {
		padding: 14rpx 0;
	}

	.tui-attr {
		font-size: 24rpx;
		color: #999;
		padding: 6rpx 0;
	}

	.tui-cmt-btn {
		padding: 50rpx 0 30rpx 0;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-nomore-box {
		padding-top: 10rpx;
	}

	.tui-product-img {
		display: flex;
		flex-direction: column;
		transform: translateZ(0);
	}

	.tui-product-img image {
		width: 100%;
		display: block;
	}

	/*底部操作栏*/

	.tui-col-7 {
		width: 58.33333333%;
	}

	.tui-col-5 {
		width: 41.66666667%;
	}

	.tui-operation {
		width: 100%;
		height: 100rpx;
		background: rgba(255, 255, 255, 0.98);
		position: fixed;
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 10;
		bottom: 0;
		left: 0;
		/* padding-bottom: env(safe-area-inset-bottom); */
	}

	.tui-safearea-bottom {
		width: 100%;
		height: env(safe-area-inset-bottom);
	}

	.tui-operation::before {
		content: '';
		position: absolute;
		top: 0;
		right: 0;
		left: 0;
		border-top: 1rpx solid #eaeef1;
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
	}

	.tui-operation-left {
		display: flex;
		align-items: center;
	}

	.tui-operation-item {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		position: relative;
	}

	.tui-operation-text {
		font-size: 22rpx;
		color: #333;
	}

	.tui-opacity {
		opacity: 0.5;
	}

	.tui-scale-small {
		transform: scale(0.9);
		transform-origin: center center;
	}

	.tui-operation-right {
		height: 100rpx;
		padding: 0 12rpx;
		box-sizing: border-box;
	}

	.tui-right-flex {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-flex-1 {
		flex: 1;
		padding: 6rpx;
	}

	/*底部操作栏*/

	/*底部选择弹层*/

	.tui-popup-class {
		border-top-left-radius: 24rpx;
		border-top-right-radius: 24rpx;
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-popup-box {
		position: relative;
		padding: 30rpx 0 100rpx 0;
	}

	.tui-popup-btn {
		width: 100%;
		position: absolute;
		left: 0;
		bottom: 0;
	}

	/* .tui-popup-btn .tui-btn-class {
		width: 90% !important;
		display: block !important;
		font-size: 28rpx !important;
	} */

	/* .tui-icon-close {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
	} */

	.tui-product-box {
		display: flex;
		align-items: flex-end;
		font-size: 24rpx;
		padding-bottom: 30rpx;
	}

	.tui-popup-img {
		height: 200rpx;
		width: 200rpx;
		border-radius: 24rpx;
		display: block;
	}

	.tui-popup-price {
		padding-left: 20rpx;
		padding-bottom: 8rpx;
	}

	.tui-amount {
		color: #ff201f;
		font-size: 36rpx;
	}

	.tui-number {
		font-size: 24rpx;
		line-height: 24rpx;
		padding-top: 12rpx;
		color: #999;
	}

	.tui-popup-scroll {
		height: 600rpx;
		font-size: 26rpx;
	}

	.tui-scrollview-box {
		padding: 0 30rpx 60rpx 30rpx;
		box-sizing: border-box;
	}

	.tui-attr-title {
		padding: 10rpx 0;
		color: #333;
	}

	.tui-attr-box {
		font-size: 0;
		padding: 20rpx 0;
	}

	.tui-attr-item {
		max-width: 100%;
		min-width: 200rpx;
		height: 64rpx;
		display: -webkit-inline-flex;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		background: #f7f7f7;
		padding: 0 26rpx;
		box-sizing: border-box;
		border-radius: 32rpx;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		font-size: 26rpx;
	}

	.tui-attr-active {
		background: #fcedea !important;
		color: #e41f19;
		font-weight: bold;
		position: relative;
	}

	.tui-attr-active::after {
		content: '';
		position: absolute;
		border: 1rpx solid #e41f19;
		width: 100%;
		height: 100%;
		border-radius: 40rpx;
		left: 0;
		top: 0;
	}

	.tui-number-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 0 30rpx 0;
		box-sizing: border-box;
	}

	/*底部选择弹层*/

	/*分享弹层*/
	.tui-share__box {
		width: 100%;
		height: 380rpx;
		background-color: #fff;
	}

	.tui-share__header {
		padding: 40rpx 0;
		text-align: center;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		text-align: center;
		position: relative;
	}

	.tui-close__box {
		position: absolute;
		right: 25rpx;
		top: 25rpx;
	}

	.tui-share__list {
		width: 100%;
		padding-top: 20rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tui-share__item {
		flex: 1;
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.tui-share__item image {
		width: 120rpx;
		height: 120rpx;
	}

	.tui-share__text {
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		padding-top: 18rpx;
	}

	/*海报modal弹层*/
	.tui-poster__canvas {
		background-color: #fff;
		position: absolute;
		left: -9999px;
	}

	.tui-poster__box {
		width: 100%;
		position: relative;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.tui-close__img {
		width: 48rpx;
		height: 48rpx;
		position: absolute;
		right: 0;
		top: -60rpx;
	}

	.tui-poster__img {
		width: 560rpx;
		height: 890rpx;
		border-radius: 20rpx;
		margin-bottom: 40rpx;
	}

	.tui-share__tips {
		font-size: 24rpx;
		transform: scale(0.8);
		transform-origin: center center;
		color: #ffffff;
		padding-top: 12rpx;
	}
</style>